package com.xiangyi.teachingsystem.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiangyi.teachingsystem.entity.dto.MsgListDto;
import com.xiangyi.teachingsystem.entity.po.ShortMsg;
import com.xiangyi.teachingsystem.entity.vo.Result;
import com.xiangyi.teachingsystem.service.ShortMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class ShortMsgController {
    @Autowired
    ShortMsgService shortMsgService;

    @PostMapping("/sendMsg")
    public Result sendMsg(@Validated @RequestBody ShortMsg shortMsg){
        try {
            shortMsgService.save(shortMsg);
            return Result.success("消息发送成功");
        }catch (Exception e){
            e.printStackTrace();
            return Result.failure("服务器错误").setData(e.getMessage());
        }
    }

    @GetMapping("/msgInfoList")
    public Result msgInfoList(@RequestParam String msgSpace){
        try {
            List<ShortMsg> msg_space = shortMsgService.msgInfoList(msgSpace);
            return Result.success("消息内容查询成功").setData(msg_space);
        }catch (Exception e){
            e.printStackTrace();
            return Result.failure("服务器错误").setData(e.getMessage());
        }
    }

    @GetMapping("/userMsgList")
    public Result msglist(@RequestParam Integer id){
        try {
            List<MsgListDto> msgList=shortMsgService.msgList(id);
            return Result.success("消息列表查询成功").setData(msgList);
        }catch (Exception e){
            e.printStackTrace();
            return Result.failure("服务器错误").setData(e.getMessage());
        }
    }
}
